#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@File Name  : local_file.py
@Author     : LeeCQ
@Date-Time  : 2019/12/6 19:36

<<<<<<< HEAD
处理本地文件：修改文件名；

"""

import urllib.parse
import os
import re


class LifeAndHeartLocalFileName:
    """重命名本地下载的视频"""
    def __init__(self):
        self.path = r'C:\Users\LCQ\Downloads\Video\lifeAndHeart\\'

    def get_name_from_txt(self):
        with open('./sup/listURL.txt', 'r', encoding='utf8') as fd:
            text = fd.read().split('\n')
            return [x.split('\t')[0] for x in text if len(x) > 10 and not x.startswith('\t')]

    def renames(self):
        name = self.get_name_from_txt()

        os.chdir(self.path)
        id_ = [re.findall(r'([\d]\.[\d])', x)[0] for x in os.listdir('.')]  # 获取ID
        print(id_)

        a = [urllib.parse.unquote(name) for name in os.listdir('.')]        # 文件名URL解码
        a = [x for x in zip(os.listdir('.'), [i+'_'+n+'.mp4' for i, n in zip(id_, name)])]  # 新文件名构造
        a = [os.rename(old, new) for old, new in a]     # rename ()
        print("修改了", len(a), "个文件。")

        os.chdir(os.path.dirname(__file__))


if __name__ == '__main__':
    LifeAndHeartLocalFileName().renames()
=======
"""
>>>>>>> 0f663d9cdbaca672411c54e3f484639a12f0b328
